package com.zhr.handler;

import com.zhr.server.WeixinRequest;
import com.zhr.server.WeixinResponse;
import com.zhr.type.Event;
import com.zhr.type.MsgType;

public class MessageEventHandler extends MessageAbstractHandler {

	private final String HELLO_WORLD = "Hi！欢迎关注`你的平台`！发送消息有不同惊喜哦，[玫瑰]同时`你的平台`还会继续添加功能，敬请期待呦！\n功能列表：\n1、你说什么我也说什么;\n2、帮你计算(如：24 8 3 3 3)";

	private final String BYE_WORLD = "不要这样子啦，伦家还是会成长的啦。。。";

	private final String CLICK_WORLD = "按这里，按那里。。。";

	@Override
	public WeixinResponse handle(WeixinRequest request) {
		Event event = null;
		try {
			event = Event.valueOf(request.getEvent());
		} catch (Exception e) {
		}
		WeixinResponse response = super.handle(request);
		response.setFuncFlag("1");
		response.setMsgType(MsgType.text.name());
		String responseContent = "";
		if (Event.subscribe == event) {
			responseContent = HELLO_WORLD;
		} else if (Event.unsubscribe == event) {
			responseContent = BYE_WORLD;
		} else if (Event.CLICK == event) {
			responseContent = CLICK_WORLD;
		}
		response.setContent(responseContent);
		return response;
	}

	@Override
	public int getPriority() {
		return MAX_PRIORITY;
	}

	@Override
	public boolean accpet(WeixinRequest request) {
		Event event = null;
		try {
			event = Event.valueOf(request.getEvent());
		} catch (Exception e) {
		}

		return Event.subscribe == event || Event.unsubscribe == event
				|| Event.CLICK == event;
	}

}
